package com.numbfish.ch16_ex06_web_flux.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello(@RequestParam(value = "key",required = false,defaultValue = "默认key") String key){
        return "hello world !!!key"+key;
    }

    // 推荐方式
    // 返回单个数据 Mono：

    @GetMapping("/single")
    public Mono<String> single(@RequestParam(value = "key",required = false,defaultValue = "默认key") String key){
        Mono<String> mono = Mono.just("single world !!!key"+key);
        return mono;
    }
    //http://localhost:8080/list
    // 返回多个数据 Flux:
    @GetMapping("/list")
    public Flux<String> many(@RequestParam(value = "key",required = false,defaultValue = "默认key") String key){
        Flux<String> flux = Flux.just("many world !!!key"+key);
        return flux;
    }
}
